package com.product.android.commonInterface.contact;

import org.json.JSONException;
import org.json.JSONObject;

import com.common.android.utils.JSONUtils;
import com.product.android.business.ApplicationVariable;

public class OapApp {
	
	private long uid;
	//应用编号（8位整型）
	public  int appid;
	//唯一标识（16位字符）
	public String code;
	//权限名称（64位字符）
	public String name;
	//菜单分类（8位字符）
	public String menutype;
	
	//访问地址（255位字符）type=web时返回web版url，type=3g时返回 3g 版url
	public String open_url;
	//业务处理URL（255位字符）type=web时返回web版url，type=3g时返回 3g 版url
	public String buss_url;
	//平台配置信息
	public String packet_name;
	public String product_code;
	//打开目标（16位字符）
	public String target;
	//是否显示（-1=不显示 0=菜单显示)
	public int display;
	
	//最新的产品版本号（11位整型）
	public int ver;
	
	//强制升级版本（不得大于当前ver）
	public int coercever;	
	
	//版本名称（20位字符串）
	public String vername;
	//下载地址
	public String down_url;
	//md5验证码 
	public String md5;
	//版本更新履历
	public String notes;
	
	//默认0表示本地应用，1表示服务器应用
	public int isLocal = 0; 
	//本地应用存图片，从服务端得到的应用res为空
	public int res = 0;
	
	public int updatetime = 0;
	
	private String cfg;
	private JSONObject temp = null;
	
	private boolean hasnewver;

	//菜单分类名称
	public String typename;
	public String getTypename() {
		return typename;
	}

	public void setTypename(String typename) {
		this.typename = typename;
	}
	//显示菜单目录
	public boolean displayType = false;
	public void setDisplayType(boolean displayType) {
		this.displayType = displayType;
	}

		
	//菜单
	public void initValueByMenuJson(JSONObject json){
		uid = ApplicationVariable.INSTANCE.getIUser().getOapUid();
		appid = JSONUtils.getInt(json, "appid");
		code = JSONUtils.getString(json, "code");
		name = JSONUtils.getString(json, "name");
		menutype = JSONUtils.getString(json, "menutype");
		open_url = JSONUtils.getString(json, "url");
//		if(open_url != null && !"".equals(open_url)){
//			open_url = open_url.replaceAll("\\{SID\\}", 
//											ApplicationVariable.INSTANCE.getCurrentUserInfo().getSessionId())
//					.replaceAll("\\{UID\\}", ApplicationVariable.INSTANCE.getCurrentUserInfo().getOapUid()+"");
//		}
		buss_url = JSONUtils.getString(json, "bussurl");
		
		cfg = JSONUtils.getString(json, "cfg");
		if(cfg != null && !"".equals(cfg) && !cfg.equals("null")){
			try {
				temp = new JSONObject(cfg);
				temp = JSONUtils.getJSONObject(temp, "30");
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			if(temp != null){
				packet_name = JSONUtils.getString(temp, "packet_name");
				product_code = JSONUtils.getString(temp, "product_code");
			}
		}

		target = JSONUtils.getString(json, "target");
		display = JSONUtils.getInt(json, "display");
		updatetime = JSONUtils.getInt(json, "updatetime");
		isLocal = 1 ;
	}
	
	public int getDisplay() {
		return display;
	}

	public void setDisplay(int display) {
		this.display = display;
	}

	//菜单版本信息
	public void initValueByVerJson(JSONObject json){
		ver = JSONUtils.getInt(json, "ver");
		vername = JSONUtils.getString(json, "vername");
		down_url = JSONUtils.getString(json, "url");
		md5 = JSONUtils.getString(json, "md5");
		notes = JSONUtils.getString(json, "notes");
		coercever = JSONUtils.getInt(json, "coercever");
	}
	
	public long getUid() {
		return uid;
	}

	public void setUid(long uid) {
		this.uid = uid;
	}

	public int getAppid() {
		return appid;
	}

	public void setAppid(int appid) {
		this.appid = appid;
	}
	
	public int getRes() {
		return res;
	}

	public void setRes(int res) {
		this.res = res;
	}
	
	public int getIsLocal() {
		return isLocal;
	}

	public void setIsLocal(int isLocal) {
		this.isLocal = isLocal;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getMenutype() {
		return menutype;
	}

	public void setMenutype(String menutype) {
		this.menutype = menutype;
	}

	public String getOpen_url() {
		return open_url;
	}

	public void setOpen_url(String open_url) {
		this.open_url = open_url;
	}

	public String getBuss_url() {
		return buss_url;
	}

	public void setBuss_url(String buss_url) {
		this.buss_url = buss_url;
	}

	public String getPacket_name() {
		return packet_name;
	}

	public void setPacket_name(String packet_name) {
		this.packet_name = packet_name;
	}

	public String getProduct_code() {
		return product_code;
	}

	public void setProduct_code(String product_code) {
		this.product_code = product_code;
	}

	public String getTarget() {
		return target;
	}

	public void setTarget(String target) {
		this.target = target;
	}

	public int getVer() {
		return ver;
	}

	public void setVer(int ver) {
		this.ver = ver;
	}

	public String getVername() {
		return vername;
	}

	public void setVername(String vername) {
		this.vername = vername;
	}

	public String getDown_url() {
		return down_url;
	}

	public void setDown_url(String down_url) {
		this.down_url = down_url;
	}

	public String getMd5() {
		return md5;
	}

	public void setMd5(String md5) {
		this.md5 = md5;
	}

	public String getNotes() {
		return notes;
	}

	public void setNotes(String notes) {
		this.notes = notes;
	}

	public boolean isHasnewver() {
		return hasnewver;
	}

	public void setHasnewver(boolean hasnewver) {
		this.hasnewver = hasnewver;
	}

	@Override
	public String toString() {
		return "OapApp [uid=" + uid + ", appid=" + appid + ", code=" + code
				+ ", name=" + name + ", menutype=" + menutype + ", open_url="
				+ open_url + ", buss_url=" + buss_url + ", packet_name="
				+ packet_name + ", product_code=" + product_code + ", target="
				+ target + ", ver=" + ver + ", vername=" + vername
				+ ", down_url=" + down_url + ", md5=" + md5 + ", notes="
				+ notes + "]";
	}
}